package com.fanrui.code.family;

import java.util.Map;

import com.fanrui.code.config.ConfigFileManager;
import com.fanrui.code.entity.FamilyJob;

/**
 * 俱乐部职位
 * @author Administrator
 *
 */
public class FamilyJobConfig {

	public static final int NORMALJOBID = 3;
	
	public static final int OWERJOBID = 1;
	
	// singleton
	private FamilyJobConfig() {
	}

	private static class FamilyJobConfigSingleton {
		private static FamilyJobConfig instance = new FamilyJobConfig();
	}

	public static FamilyJobConfig getInstance() {
		return FamilyJobConfigSingleton.instance;
	}
	
	/**
	 * 俱乐部职位配置
	 */
	private Map<Integer, FamilyJob> familyJobConfigs = null;

	public void init() {
		familyJobConfigs = ConfigFileManager.getInstance().getConfigFilesByName(FamilyJob.class);
	}
	
	/**  
	*  创建一个家族职位
	*  @param jobId
	*  @return    
	*  FamilyJobEntity    
	*/  
	public FamilyJobEntity createFamilyJobEntity(Integer jobId){
		if(jobId == null || !familyJobConfigs.containsKey(jobId)){
			return getNormalFamilyEntity();
		}
		return new FamilyJobEntity(familyJobConfigs.get(jobId));
		
	}
	
	/**  
	*  根据职位ID判断是否有操作某件事的权限
	*  1 解散家族 2 修改公告 3 同意入圈 4 踢出成员 5修改职务 6设为族长
	*/  
	public boolean isCanOperation(int jobId, int operrationId) {
		if (familyJobConfigs != null && !familyJobConfigs.isEmpty()) {
			for (FamilyJob config : familyJobConfigs.values()) {
				if (config.getId() == jobId+1) {
					String[] ss = config.getJobCompetence().split(",");
					for(String s : ss) {
						try {
							if(Integer.parseInt(s) == operrationId) {
								return true;
							}
						} catch (Exception e) {
							return false;
						}
					}
				}
			}
		}
		return false;
	}
	
	public FamilyJobEntity getNormalFamilyEntity(){
		return new FamilyJobEntity(familyJobConfigs.get(NORMALJOBID));
	}
	
	enum ClubOperation {
		DissClub,
		ReviseBulletin
	}
}
